﻿Option Infer On
Imports Microsoft.Reporting.WinForms

Public Class frmMain
    Private Function GetSummaryMessage() As String
        Dim Summary As String = ""
        Dim Greeting As String = ""
        Dim Employee As String = ""
        Dim Models As String = ""
        Dim Visits As String = ""
        Dim VisitDetails As String = ""
        Dim Survey As String = ""
        Dim EmployeeNumber As Integer = EmployeeTableAdapter.CountEmployee()
        Dim ModelNumber As Integer = InventoryTableAdapter.CountInventory()
        Dim VisitNumber As Integer = VisitTableAdapter.CountVisit()
        Dim VisitDetailNumber As Integer = VisitdetailsTableAdapter.CountVisitDetails()
        Dim SurveyNumber As Integer = SurveyTableAdapter.CountSurvey()
        Dim MilTime As String = Format(Now(), "HH:mm:ss")

        ' See if is morning or not
        If MilTime < "12:00:00" Then
            Greeting = "Good Morning,"
        ElseIf MilTime >= "12:00:00" And _
               MilTime < "19:00:00" Then
            Greeting = "Good Afternoon,"
        Else
            Greeting = "Good Evening,"
        End If

        ' We will now determine the correct message 
        ' given the amount of employees registered

        If EmployeeNumber = 0 Then
            Employee = "Currently, we have no employees registered in the database."
        ElseIf EmployeeNumber = 1 Then
            Employee = "Currently, we have one employee registered in the database."
        Else
            Employee = "We currently have " & EmployeeNumber & " employees registered in the database."
        End If

        If ModelNumber = 0 Then
            Models = "We have no car models registered yet."
        ElseIf ModelNumber = 1 Then
            Models = "Currently, we only have one car model registered."
        Else
            Models = "We also have " & ModelNumber & " car models registered."
        End If

        If VisitNumber = 0 Then
            Visits = "There are no visits in our record."
        ElseIf VisitNumber = 1 Then
            Visits = "There is only one visit in our record."
        Else
            Visits = "There are " & VisitNumber & " visits that were recorded."
        End If

        If VisitNumber = 1 And VisitDetailNumber = 1 Then
            VisitDetails = "That visit has details filled too."
        ElseIf VisitNumber > 1 And VisitDetailNumber = 1 Then
            VisitDetails = "We have filled details for one of them."
        ElseIf VisitDetailNumber > 1 Then
            VisitDetails = "We have filled details for " & VisitDetailNumber & " of them."
        End If

        If SurveyNumber = 0 Then
            Survey = "Finally, we have no surveys filled yet."
        ElseIf SurveyNumber = 1 Then
            Survey = "Finally, we have one survey filled."
        Else
            Survey = "Finally, there are " & SurveyNumber & " surveys filled."
        End If

        Summary = Greeting & vbCrLf & vbCrLf & Employee & vbCrLf & _
                  Models & vbCrLf & Visits & vbCrLf & VisitDetails _
                  & vbCrLf & Survey

        Return Summary
    End Function

    Private Sub btnEmployee_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnEmployee.Click
        SwitchForm(My.Forms.frmViewEmployee)
    End Sub

    Private Sub btnInventory_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnInventory.Click
        SwitchForm(My.Forms.frmViewInventory)
    End Sub

    Private Sub btnSurvey_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSurvey.Click
        SwitchForm(My.Forms.frmSurvey)
    End Sub

    Private Sub btnDetailedSurvey_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
        SwitchForm(My.Forms.frmDetailedVisit)
    End Sub

    Private Sub btnVisitMain_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnVisit.Click
        SwitchForm(My.Forms.frmQuickVisit)
    End Sub

    Private Sub frmMain_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        'Hide Main menu labels

        'lblHome.Visible = False
        lblVisit.Visible = False
        lblSurvey.Visible = False
        lblStatistics.Visible = False
        lblInventory.Visible = False
        lblEmployee.Visible = False
        lblClose.Visible = False


        'TODO: This line of code loads data into the 'Atlantic_toyota_atm_dbDataSet.topcarsreport' table. You can move, or remove it, as needed.
        Me.TopcarsreportTableAdapter.Fill(Me.Atlantic_toyota_atm_dbDataSet.topcarsreport)
        'TODO: This line of code loads data into the 'Atlantic_toyota_atm_dbDataSet.visitdetails' table. You can move, or remove it, as needed.
        Me.VisitdetailsTableAdapter.Fill(Me.Atlantic_toyota_atm_dbDataSet.visitdetails)
        'TODO: This line of code loads data into the 'Atlantic_toyota_atm_dbDataSet.visit' table. You can move, or remove it, as needed.
        Me.VisitTableAdapter.Fill(Me.Atlantic_toyota_atm_dbDataSet.visit)
        'TODO: This line of code loads data into the 'Atlantic_toyota_atm_dbDataSet.survey' table. You can move, or remove it, as needed.
        Me.SurveyTableAdapter.Fill(Me.Atlantic_toyota_atm_dbDataSet.survey)
        'TODO: This line of code loads data into the 'Atlantic_toyota_atm_dbDataSet.inventory' table. You can move, or remove it, as needed.
        Me.InventoryTableAdapter.Fill(Me.Atlantic_toyota_atm_dbDataSet.inventory)
        'TODO: This line of code loads data into the 'Atlantic_toyota_atm_dbDataSet.employee' table. You can move, or remove it, as needed.
        Me.EmployeeTableAdapter.Fill(Me.Atlantic_toyota_atm_dbDataSet.employee)
        Dim sOut As String = ""
        InitImageLists()

        ' query for "Win32_Processor" class under WMI          
        Dim wmiQuery As New Management.ObjectQuery("select Name from Win32_Processor")
        ' searcher is what runs the query, set the Query object as a parameter       
        Dim wmiSearch As New Management.ManagementObjectSearcher(wmiQuery)
        ' loop thru all properties and display the values       
        For Each wmiObject As System.Management.ManagementObject In wmiSearch.Get()
            For Each wmiProperty As Management.PropertyData In wmiObject.Properties
                If Not wmiProperty.Value Is Nothing Then
                    sOut = wmiProperty.Value.ToString
                End If
            Next
        Next



        Dim RAM As Integer = System.Math.Ceiling((My.Computer.Info.TotalPhysicalMemory / 1024) / 1024)
        lblOsInfo.Text = My.Computer.Info.OSFullName
        lblServicePack.Text = Environment.OSVersion.ServicePack
        lblVersion.Text = My.Application.Info.Version.ToString
        lblProcessor.Text = RemoveExtraWhiteSpaces(sOut)
        lblIP.Text = "IP Address: " & GetIPAddress()
        lblDate.Text = "Date: " & Now.ToLongDateString
        lblSummary.Text = GetSummaryMessage()

        cmbShortActivities.SelectedItem = "Fill a Visit"
        cmbShortReports.SelectedItem = cmbShortReports.Items.Item(0)



    End Sub

    Private Sub btnCloseMain_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClose.Click
        Dim Confirmation As MsgBoxResult
        Confirmation = MessageBox.Show("Unsaved changes will be lost. Are you sure you want to exit?", _
                                       "Confirmation", MessageBoxButtons.YesNo, MessageBoxIcon.Question)
        If Confirmation = MsgBoxResult.Yes Then
            CloseAllForms()
        End If
    End Sub

    Private Sub btnStatistics_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnStatistics.Click
        SwitchForm(My.Forms.frmStatistics)
    End Sub

    Private Sub tmrGeneral_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tmrGeneral.Tick
        ' Update Clock
        lblClock.Text = "Hour: " & Now.ToLongTimeString()

        ' Update memory usage
        lblRam.Text = Math.Round((My.Computer.Info.AvailablePhysicalMemory / 1024) / 1024, 2) & _
              " MB of " & Math.Ceiling((My.Computer.Info.TotalPhysicalMemory / 1024) / 1024) & _
              " MB RAM " & vbCrLf & Math.Round(((Math.Round((My.Computer.Info.AvailablePhysicalMemory / 1024) / 1024, 2)) / _
                            (Math.Ceiling((My.Computer.Info.TotalPhysicalMemory / 1024) / 1024))) * 100, 2) & "% Memory Used"

    End Sub

    ' Mouse Hoover
    Private Sub btnGoActivities_Hoover(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnGoActivities.MouseHover
        btnGoActivities.FlatAppearance.BorderColor = Color.DeepSkyBlue
    End Sub

    Private Sub btnGoReports_Hoover(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnGoReports.MouseHover
        btnGoReports.FlatAppearance.BorderColor = Color.DeepSkyBlue
    End Sub


    ' Mouse Leave
    Private Sub btnGoActivities_Leave(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnGoActivities.MouseLeave
        btnGoActivities.FlatAppearance.BorderColor = Color.DimGray
    End Sub

    Private Sub btnGoReports_Leave(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnGoReports.MouseLeave
        btnGoReports.FlatAppearance.BorderColor = Color.DimGray
    End Sub

    Private Sub btnGoActivities_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnGoActivities.Click
        Select Case cmbShortActivities.SelectedItem
            Case "Fill a Visit"
                SwitchForm(My.Forms.frmQuickVisit)
            Case "Fill a Survey"
                SwitchForm(My.Forms.frmSurvey)
            Case "View Current Models"
                SwitchForm(My.Forms.frmViewInventory)
            Case "Add New Models"
                SwitchForm(My.Forms.frmAddInventory)
            Case "Delete Models"
                SwitchForm(My.Forms.frmDeleteInventory)
            Case "View Employees"
                SwitchForm(My.Forms.frmViewEmployee)
            Case "Add Employees"
                SwitchForm(My.Forms.frmAddEmployee)
            Case "Delete Employees"
                SwitchForm(My.Forms.frmDeleteEmployee)
        End Select
    End Sub

    Private Sub btnGoReports_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnGoReports.Click
        Select Case cmbShortReports.SelectedItem
            Case "Sells Report"
                My.Forms.frmSellsReport.Show()
                My.Forms.frmSellsReport.ReportViewer.Refresh()
            Case "Employee Performance Report"
                My.Forms.frmEmployeePerformanceReport.Show()
                My.Forms.frmEmployeePerformanceReport.ReportViewer.Refresh()
            Case "Inventory Report"
                My.Forms.frmInventoryReport.Show()
                My.Forms.frmInventoryReport.ReportViewer.Refresh()
            Case "Employee Report"
                My.Forms.frmEmployeeReport.Show()
                My.Forms.frmEmployeeReport.ReportViewer.Refresh()
            Case "Visit Report"
                My.Forms.frmQuickVisitReport.Show()
                My.Forms.frmQuickVisitReport.ReportViewer.Refresh()
            Case "Detailed Visit Report"
                My.Forms.frmDetailedVisitReport.Show()
                My.Forms.frmDetailedVisitReport.ReportViewer.Refresh()
            Case "Results By Age"
                My.Forms.frmResultsByAge.Show()
                My.Forms.frmResultsByAge.ReportViewer.Refresh()
            Case "Results By Town"
                My.Forms.frmResultsByTown.Show()
                My.Forms.frmResultsByTown.ReportViewer.Refresh()
            Case "Results By Gender"
                My.Forms.frmResultsByGender.Show()
                My.Forms.frmResultsByGender.ReportViewer.Refresh()
            Case "Publicity Results"
                My.Forms.frmPublicityResults.Show()
                My.Forms.frmPublicityResults.ReportViewer.Refresh()
        End Select
    End Sub

    '************************************************
    ' Show the label for the items on the main menu *
    '************************************************

    Private Sub btnVisit_MouseOver(ByVal sender As System.Object, _
                  ByVal e As System.EventArgs) Handles btnVisit.MouseHover
        lblVisit.Visible = True
    End Sub

    Private Sub btnSurvey_MouseOver(ByVal sender As System.Object, _
                  ByVal e As System.EventArgs) Handles btnSurvey.MouseHover
        lblSurvey.Visible = True
    End Sub

    Private Sub btnStatistics_MouseOver(ByVal sender As System.Object, _
                  ByVal e As System.EventArgs) Handles btnStatistics.MouseHover
        lblStatistics.Visible = True
    End Sub

    Private Sub btnInventory_MouseOver(ByVal sender As System.Object, _
                  ByVal e As System.EventArgs) Handles btnInventory.MouseHover
        lblInventory.Visible = True
    End Sub

    Private Sub btnEmployee_MouseOver(ByVal sender As System.Object, _
                  ByVal e As System.EventArgs) Handles btnEmployee.MouseHover
        lblEmployee.Visible = True
    End Sub

    Private Sub btnClose_MouseOver(ByVal sender As System.Object, _
                  ByVal e As System.EventArgs) Handles btnClose.MouseHover
        lblClose.Visible = True
    End Sub


    '**************************************
    ' Hides the labels from the main menu *
    '**************************************

    Private Sub btnVisit_MouseLeave(ByVal sender As System.Object, _
                  ByVal e As System.EventArgs) Handles btnVisit.MouseLeave
        lblVisit.Visible = False
    End Sub

    Private Sub btnSurvey_MouseLeave(ByVal sender As System.Object, _
                  ByVal e As System.EventArgs) Handles btnSurvey.MouseLeave
        lblSurvey.Visible = False
    End Sub

    Private Sub btnStatistics_MouseLeave(ByVal sender As System.Object, _
                  ByVal e As System.EventArgs) Handles btnStatistics.MouseLeave
        lblStatistics.Visible = False
    End Sub

    Private Sub btnInventory_MouseLeave(ByVal sender As System.Object, _
                  ByVal e As System.EventArgs) Handles btnInventory.MouseLeave
        lblInventory.Visible = False
    End Sub

    Private Sub btnEmployee_MouseLeave(ByVal sender As System.Object, _
                  ByVal e As System.EventArgs) Handles btnEmployee.MouseLeave
        lblEmployee.Visible = False
    End Sub

    Private Sub btnClose_MouseLeave(ByVal sender As System.Object, _
                  ByVal e As System.EventArgs) Handles btnClose.MouseLeave
        lblClose.Visible = False
    End Sub

End Class
